<template>
  <div class="ContentEva">
    <div class="headline">{{ msg.headLine }}</div>
    <div class="user">
      <div>
        <div class="imgBox">
          <img :src="msg.userImg" alt="" />
        </div>
        <div class="userBox">
          <p>{{ msg.userName }}</p>
          <p>{{ msg.time }}</p>
        </div>
      </div>
      <div class="left">关注</div>
    </div>
    <div class="content">
      <div class="imgBox" v-for="(img, index) in msg.content" :key="index">
        <img v-lazy="img" alt="" />
      </div>
      <div class="read">阅读{{ msg.number }}</div>
    </div>


    <div class="comment">
      <div class="total">共{{ msg.comments.length }}条评论</div>
      <div class="myComment">
        <img :src="msg.userImg" alt="" />
        <input type="text" placeholder="来说点什么吧..."  />
       

      </div>
      <div class="comments">
        <div
          class="commentIn"
          v-for="(comment, index) in msg.comments"
          :key="index"
        >
          <div class="userImg">
            <img :src="comment.userImg" alt="" />
          </div>
          <div class="right">
            <div class="content">
              <div class="rightLeft">
                <span>{{ comment.userName }}</span>
                <span>{{ comment.time }}</span>
              </div>
              <div class="leftLeft" @click="zan(index, comment.id)">
                {{ comment.parise }}
                <span
                  class="iconfont icon-dianzan"
                  v-if="comment.zan"
                  style="color: orange"
                ></span>
                <span class="iconfont icon-dianzan" v-else></span>
              </div>
            </div>
            <div class="realComment">{{ comment.content }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

//chuang
import axios from "axios";

export default {
  name: "ContentEva",
  props: ["msg"],
  data() {
    return {
      zanId: [],
      show: false,
      value:"",
    };
  },
  methods: {
    zan(idx, id) {
      this.msg.number++;
      if (this.msg.comments[idx].zan == false) {
        this.msg.comments[idx].parise++;
        this.zanId.push(id);
        this.msg.comments[idx].zan = !this.msg.comments[idx].zan;
      } else {
        this.msg.comments[idx].parise--;
        this.msg.comments[idx].zan = !this.msg.comments[idx].zan;
        for (let i = 0; i < this.zanId.length; i++) {
          if (this.zanId[i] == id) {
            this.zanId.splice(i, 1);
          }
        }
      }

      // patch是更新数据用的，更新谁就要请求路径就要具体到谁
      let json = this.msg;
      axios({
        url: "/userShareZ/" + this.msg.id,
        method: "patch",
        data: json,
      })
        .then((res) => {
          console.log("patch", res.data);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  watch: {
    msg: {
      handler(newVal, oldVal) {
        // console.log(this.msg);
        this.msg.number++;
        axios({
          url: "/userShareZ/" + this.msg.id,
          method: "patch",
          data: this.msg,
        }).then((res) => {
          // console.log(res.data)
        });
      },
    },
  },
};
</script>

<style scoped>
.ContentEva {
  box-sizing: border-box;
  padding: 0 0.1rem;
  margin-top: 0.5rem;
  width: 100%;
  margin-bottom: 0.4rem;
}
.user {
  box-sizing: border-box;
  padding: 0.15rem 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user .imgBox {
  width: 0.15rem;
  height: 0.15rem;
  border-radius: 50%;
}
.user .imgBox img {
  width: 0.2rem;
  height: 0.2rem;
  border-radius: 50%;
}
.userBox {
  font-size: 12px;
  padding: 0 0.15rem;
  /* transform: scale(calc(10 / 12)); */
}
.user div:nth-child(1) {
  display: flex;
  align-items: center;
}
.user .left {
  border-radius: 0.15rem;
  border: 1px solid orange;
  padding: 0.01rem 0.08rem;
  color: orange;
}

.content {
  width: 100%;
}
.content .imgBox {
  width: 100%;
  border-radius: 0.1rem;
  box-sizing: border-box;
  padding: 0 0.1rem;
  margin-top: 0.15rem;
}
.content .imgBox img {
  width: 100%;
  border-radius: 0.1rem;
}
.read {
  font-size: 14px;
  color: rgb(201, 195, 195);
  margin: 0.25rem 0;
}

.comment {
  width: 100%;
  padding-top: 0.3rem;
  border-top: 1px solid rgb(199, 195, 195);
}
.total {
  font-size: 14px;
  color: rgb(165, 162, 162);
}
.myComment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.1rem;
}
.myComment img {
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  margin: 0 0.1rem;
  margin-left: 0;
}
.myComment input {
  font-size: 14px;
  background-color: rgb(223, 219, 219);
  border-radius: 0.1rem;
  flex: 1;
  height: 0.25rem;
  padding: 0 0.1rem;
}
.comments {
  margin-top: 0.15rem;
}
.commentIn {
  margin-top: 0.15rem;
  display: flex;
  border-bottom: 1px solid rgb(196, 193, 193);
  padding-bottom: 0.15rem;
}
.commentIn .userImg img {
  width: 0.3rem;
  height: 0.3rem;
  border-radius: 50%;
  margin-right: 0.1rem;
  margin-top: 0.05rem;
}
.right {
  flex: 1;
}
.right .content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.14rem;
  color: rgb(196, 193, 193);
}
.realComment {
  color: grey;
  font-size: 14px;
}
.popup{
  border-radius: .1rem .1rem 0 0;
}
.top{
  margin-top: .1rem;
  display: flex;
  justify-content: space-between;
}
.top button{
  padding: 0 .1rem;
  border: 0;
  background-color: #fff;
}

</style>